oid_test.go 1022 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package lfsutil
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestValidOID(t *testing.T) {
  10. tests := []struct {
  11. name string
  12. oid OID
  13. expVal bool
  14. }{
  15. {
  16. name: "malformed",
  17. oid: OID("12345678"),
  18. },
  19. {
  20. name: "unknown method",
  21. oid: OID("sha1:7c222fb2927d828af22f592134e8932480637c0d"),
  22. },
  23. {
  24. name: "sha256: malformed",
  25. oid: OID("sha256:7c222fb2927d828af22f592134e8932480637c0d"),
  26. },
  27. {
  28. name: "sha256: not all lower cased",
  29. oid: OID("sha256:EF797c8118f02dfb649607dd5d3f8c7623048c9c063d532cc95c5ed7a898a64f"),
  30. },
  31. {
  32. name: "sha256: valid",
  33. oid: OID("sha256:ef797c8118f02dfb649607dd5d3f8c7623048c9c063d532cc95c5ed7a898a64f"),
  34. expVal: true,
  35. },
  36. }
  37. for _, test := range tests {
  38. t.Run(test.name, func(t *testing.T) {
  39. assert.Equal(t, test.expVal, ValidOID(test.oid))
  40. })
  41. }
  42. }