diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ae3ec73..c65aeff 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,8 +15,8 @@ jobs: with: go-version: ${{ matrix.go-version }} - name: Install dependencies - run: go install . - - name: Unit test - run: go test ./... - - name: Build test - run: go build . + run: |- + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.59.1 + curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash + - name: CI + run: ./scripts/ci.sh diff --git a/pkg/apis/flatnetwork.pandaria.io/v1/types_test.go b/pkg/apis/flatnetwork.pandaria.io/v1/types_test.go deleted file mode 100644 index 84f1414..0000000 --- a/pkg/apis/flatnetwork.pandaria.io/v1/types_test.go +++ /dev/null @@ -1,113 +0,0 @@ -package v1_test - -import ( - "encoding/json" - "net" - "os" - "testing" - - flv1 "github.com/cnrancher/rancher-flat-network-operator/pkg/apis/flatnetwork.pandaria.io/v1" - "gopkg.in/yaml.v3" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -var subnet = flv1.FlatNetworkSubnet{ - TypeMeta: metav1.TypeMeta{ - APIVersion: "flatnetwork.pandaria.io/v1", - Kind: "FlatNetworkSubnet", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "example-macvlan-subnet", - Namespace: flv1.SubnetNamespace, - Labels: map[string]string{ - "project": "", - }, - }, - Spec: flv1.SubnetSpec{ - FlatMode: "macvlan", - Master: "eth0", - VLAN: 0, - CIDR: "192.168.1.0/24", - Mode: "", - Gateway: nil, - Ranges: []flv1.IPRange{ - { - From: net.ParseIP("192.168.1.100"), - End: net.ParseIP("192.168.1.200"), - }, - }, - Routes: []flv1.Route{}, - PodDefaultGateway: flv1.PodDefaultGateway{ - Enable: false, - ServiceCIDR: "", - }, - }, -} - -func saveYaml(obj any, path string) error { - b, _ := json.MarshalIndent(obj, "", " ") - m := map[string]any{} - err := json.Unmarshal(b, &m) - if err != nil { - return err - } - b, _ = yaml.Marshal(m) - return os.WriteFile(path, b, 0644) -} - -func Test_FlatNetworkSubnet_Macvlan(t *testing.T) { - subnet.Name = "example-macvlan-subnet" - subnet.Spec.FlatMode = "macvlan" - err := saveYaml(subnet, "../../../../docs/macvlan/subnet-example.yaml") - if err != nil { - t.Error(err) - } -} - -func Test_FlatNetworkSubnet_Macvlan_IPv6(t *testing.T) { - subnet.Name = "example-macvlan-subnet-ipv6" - subnet.Spec.FlatMode = "macvlan" - subnet.Spec.CIDR = "fd00:aaaa::/64" - subnet.Spec.Ranges = []flv1.IPRange{ - { - From: net.ParseIP("fd00:aaaa::1000"), - End: net.ParseIP("fd00:aaaa::ffff"), - }, - } - err := saveYaml(subnet, "../../../../docs/macvlan/subnet-example-ipv6.yaml") - if err != nil { - t.Error(err) - } -} - -func Test_FlatNetworkSubnet_IPvlan(t *testing.T) { - subnet.Name = "example-ipvlan-subnet" - subnet.Spec.FlatMode = "ipvlan" - subnet.Spec.CIDR = "192.168.2.0/24" - subnet.Spec.Ranges = []flv1.IPRange{ - { - From: net.ParseIP("192.168.2.100"), - End: net.ParseIP("192.168.2.150"), - }, - } - err := saveYaml(subnet, "../../../../docs/ipvlan/subnet-example.yaml") - if err != nil { - t.Error(err) - } -} - -func Test_FlatNetworkSubnet_IPvlan_IPv6(t *testing.T) { - subnet.Name = "example-ipvlan-subnet-ipv6" - subnet.Spec.FlatMode = "ipvlan" - subnet.Spec.CIDR = "fd00:eeee::/64" - subnet.Spec.Ranges = []flv1.IPRange{ - { - From: net.ParseIP("fd00:eeee::1000"), - End: net.ParseIP("fd00:eeee::ffff"), - }, - } - err := saveYaml(subnet, "../../../../docs/ipvlan/subnet-example-ipv6.yaml") - if err != nil { - t.Error(err) - } -} diff --git a/scripts/validate.sh b/scripts/validate.sh index 1df5276..dc841a9 100755 --- a/scripts/validate.sh +++ b/scripts/validate.sh @@ -4,6 +4,12 @@ set -euo pipefail cd $(dirname $0)/.. WORKINGDIR=$(pwd) +if [ -n "$(git status --porcelain --untracked-files=no)" ]; then + echo 'Ensure git directory is clean before run this script:' + git status --short + exit 1 +fi + echo 'Running: go mod verify' go mod verify