Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kind.String(): fix missing case statements for iota consts in switch #256

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"math/rand"
"os"
"path/filepath"
"reflect"
"sort"
"syscall"
"testing"
Expand Down Expand Up @@ -199,12 +200,15 @@ func (k kind) String() string {
return "directory"
case rhardlink:
return "hardlink"
case rrelsymlink:
return "relsymlink"
case rabssymlink:
return "abssymlink"
case rchardev:
return "chardev"
case rnamedpipe:
return "namedpipe"
}

panic(fmt.Sprintf("unknown kind: %v", int(k)))
}

Expand Down Expand Up @@ -431,3 +435,42 @@ func expectedResourceList(root string, resources []dresource) ([]Resource, error

return manifestResources, nil
}

func TestKindString(t *testing.T) {
kinds := []kind{
rfile,
rdirectory,
rhardlink,
rrelsymlink,
rabssymlink,
rchardev,
rnamedpipe,
}

expected := []string{
"file",
"directory",
"hardlink",
"relsymlink",
"abssymlink",
"chardev",
"namedpipe",
}

var actual []string
for _, k := range kinds {
actual = append(actual, k.String())
}
if !reflect.DeepEqual(actual, expected) {
t.Errorf("expected: %v, got: %v", expected, actual)
}

defer func() {
if r := recover(); r == nil {
t.Errorf("should panic on unknown kind")
}
}()

var unknownKind = rnamedpipe + 1
_ = unknownKind.String()
}
Loading