| 1 | // Copyright IBM Corp. 2020, 2025 |
| 2 | // SPDX-License-Identifier: MPL-2.0 |
| 3 | |
| 4 | package cidrscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/cidr`/ |
| 5 | |
| 6 | import ( |
| 7 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 8 | "testingscip-go gomod github.com/golang/go/src go1.24.0 testing/" |
| 9 | |
| 10 | "github.com/zclconf/go-cty/ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/" |
| 11 | ) |
| 12 | |
| 13 | func TestNetmaskscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/cidr`/TestNetmask().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 14 | tests := []struct { |
| 15 | Prefix ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Valuescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Value# |
| 16 | Want ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Valuescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Value# |
| 17 | Err bool |
| 18 | }{ |
| 19 | { |
| 20 | ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.StringValscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/StringVal().("192.168.1.0/24"), |
| 21 | ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.StringValscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/StringVal().("255.255.255.0"), |
| 22 | false, |
| 23 | }, |
| 24 | { |
| 25 | ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.StringValscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/StringVal().("192.168.1.0/32"), |
| 26 | ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.StringValscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/StringVal().("255.255.255.255"), |
| 27 | false, |
| 28 | }, |
| 29 | { |
| 30 | ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.StringValscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/StringVal().("0.0.0.0/0"), |
| 31 | ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.StringValscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/StringVal().("0.0.0.0"), |
| 32 | false, |
| 33 | }, |
| 34 | { |
| 35 | ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.StringValscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/StringVal().("1::/64"), |
| 36 | ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.StringValscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/StringVal().("ffff:ffff:ffff:ffff::"), |
| 37 | false, |
| 38 | }, |
| 39 | { |
| 40 | ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.StringValscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/StringVal().("not-a-cidr"), |
| 41 | ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.UnknownValscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/UnknownVal().(ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Stringscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/String.), |
| 42 | true, // not a valid CIDR mask |
| 43 | }, |
| 44 | { |
| 45 | ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.StringValscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/StringVal().("110.256.0.0/8"), |
| 46 | ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.UnknownValscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/UnknownVal().(ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Stringscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/String.), |
| 47 | true, // can't have an octet >255 |
| 48 | }, |
| 49 | } |
| 50 | |
| 51 | for _, test := range tests { |
| 52 | t.Runscip-go gomod github.com/golang/go/src go1.24.0 testing/T#Run().(fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().("cidrnetmask(%#v)", test.Prefix), func(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 53 | got, err := Netmaskscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/cidr`/Netmask().(test.Prefix) |
| 54 | |
| 55 | if test.Err { |
| 56 | if err == nil { |
| 57 | t.Fatalscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatal().("succeeded; want error") |
| 58 | } |
| 59 | return |
| 60 | } else if err != nil { |
| 61 | t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("unexpected error: %s", err) |
| 62 | } |
| 63 | |
| 64 | if !got.RawEqualsscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Value#RawEquals().(test.Want) { |
| 65 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("wrong result\ngot: %#v\nwant: %#v", got, test.Want) |
| 66 | } |
| 67 | }) |
| 68 | } |
| 69 | } |