config_test.go 789 B

1234567891011121314151617181920212223242526272829303132
  1. package fs
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestGetConfig(t *testing.T) {
  8. ctx := context.Background()
  9. // Check nil
  10. //lint:ignore SA1012 false positive when running staticcheck, we want to test passing a nil Context and therefore ignore lint suggestion to use context.TODO
  11. //nolint:staticcheck // Don't include staticcheck when running golangci-lint to avoid SA1012
  12. config := GetConfig(nil)
  13. assert.Equal(t, globalConfig, config)
  14. // Check empty config
  15. config = GetConfig(ctx)
  16. assert.Equal(t, globalConfig, config)
  17. // Check adding a config
  18. ctx2, config2 := AddConfig(ctx)
  19. config2.Transfers++
  20. assert.NotEqual(t, config2, config)
  21. // Check can get config back
  22. config2ctx := GetConfig(ctx2)
  23. assert.Equal(t, config2, config2ctx)
  24. }