github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/queue/queue_test.go (about)

     1  // Copyright 2023 The GitBundle Inc. All rights reserved.
     2  // Copyright 2017 The Gitea Authors. All rights reserved.
     3  // Use of this source code is governed by a MIT-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package queue
     7  
     8  import (
     9  	"testing"
    10  
    11  	"github.com/gitbundle/modules/json"
    12  
    13  	"github.com/stretchr/testify/assert"
    14  )
    15  
    16  type testData struct {
    17  	TestString string
    18  	TestInt    int
    19  }
    20  
    21  func TestToConfig(t *testing.T) {
    22  	cfg := testData{
    23  		TestString: "Config",
    24  		TestInt:    10,
    25  	}
    26  	exemplar := testData{}
    27  
    28  	cfg2I, err := toConfig(exemplar, cfg)
    29  	assert.NoError(t, err)
    30  	cfg2, ok := (cfg2I).(testData)
    31  	assert.True(t, ok)
    32  	assert.NotEqual(t, cfg2, exemplar)
    33  	assert.Equal(t, &cfg, &cfg2)
    34  	cfgString, err := json.Marshal(cfg)
    35  	assert.NoError(t, err)
    36  
    37  	cfg3I, err := toConfig(exemplar, cfgString)
    38  	assert.NoError(t, err)
    39  	cfg3, ok := (cfg3I).(testData)
    40  	assert.True(t, ok)
    41  	assert.Equal(t, cfg.TestString, cfg3.TestString)
    42  	assert.Equal(t, cfg.TestInt, cfg3.TestInt)
    43  	assert.NotEqual(t, cfg3, exemplar)
    44  }