github.com/octohelm/storage@v0.0.0-20240516030302-1ac2cc1ea347/pkg/datatypes/bool_test.go (about)

     1  package datatypes
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/octohelm/storage/internal/testutil"
     8  )
     9  
    10  func TestBool(t *testing.T) {
    11  	t.Run("Marshal", func(t *testing.T) {
    12  		bytes, _ := json.Marshal(BOOL_TRUE)
    13  		testutil.Expect(t, string(bytes), testutil.Equal("true"))
    14  
    15  		bytes, _ = json.Marshal(BOOL_FALSE)
    16  		testutil.Expect(t, string(bytes), testutil.Equal("false"))
    17  
    18  		bytes, _ = json.Marshal(BOOL_UNKNOWN)
    19  		testutil.Expect(t, string(bytes), testutil.Equal("null"))
    20  	})
    21  	t.Run("Unmarshal", func(t *testing.T) {
    22  		var b Bool
    23  
    24  		_ = json.Unmarshal([]byte("null"), &b)
    25  		testutil.Expect(t, b, testutil.Equal(BOOL_UNKNOWN))
    26  
    27  		_ = json.Unmarshal([]byte("true"), &b)
    28  		testutil.Expect(t, b, testutil.Equal(BOOL_TRUE))
    29  
    30  		_ = json.Unmarshal([]byte("false"), &b)
    31  		testutil.Expect(t, b, testutil.Equal(BOOL_FALSE))
    32  	})
    33  }