Skip to content

Commit

Permalink
Merge pull request #256 from thaJeztah/fix_kind
Browse files Browse the repository at this point in the history
kind.String(): fix missing case statements for iota consts in switch
  • Loading branch information
AkihiroSuda authored Oct 26, 2024
2 parents 0a983fc + 7d074e7 commit 1287117
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"math/rand"
"os"
"path/filepath"
"reflect"
"sort"
"syscall"
"testing"
Expand Down Expand Up @@ -198,12 +199,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 @@ -430,3 +434,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()
}

0 comments on commit 1287117

Please sign in to comment.