mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
f78777f784
* add new paraeters * update generated sources * run npm publish * add repositoryUrl parameter * handle registry credentials * rename parameter * handle base64encoding * remove vault reference * make username secret * add publish method * use publish method * use dedicated registry * use dry run * fix * prepend path * fix workdir * move code to npm package * do changes * update dependencies * correct property init * remomve dry-run * regenerate * add mock * add logging * add debug log * dry-run * remove try run * remove append * add debug outut * change * add debug output * changes * cleanup * use different auth property * add credential utils * add debug log outputs * remove auth handling & reuse writeFile * rename * fix debug output * remove comments * update comment * rename function * update docs * update generated files * handle npm ignore * remove commented code * add debug output
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package npm
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/magiconair/properties"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/mock"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestNewNPMRC(t *testing.T) {
|
|
type args struct {
|
|
path string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want string
|
|
}{
|
|
{name: "current dir", args: args{""}, want: configFilename},
|
|
{name: "sub dir", args: args{mock.Anything}, want: mock.Anything + "/.npmrc"},
|
|
{name: "file path in current dir", args: args{".npmrc"}, want: ".npmrc"},
|
|
{name: "file path in sub dir", args: args{mock.Anything + "/.npmrc"}, want: mock.Anything + "/.npmrc"},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := NewNPMRC(tt.args.path); !reflect.DeepEqual(got.filepath, tt.want) {
|
|
t.Errorf("NewNPMRC().filepath = %v, want %v", got.filepath, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func mockLoadProperties(t *testing.T, result *properties.Properties, err error) func(filename string, enc properties.Encoding) (*properties.Properties, error) {
|
|
return func(filename string, enc properties.Encoding) (*properties.Properties, error) {
|
|
return result, err
|
|
}
|
|
}
|
|
|
|
func TestLoad(t *testing.T) {
|
|
// init
|
|
config := NewNPMRC("")
|
|
|
|
new := properties.NewProperties()
|
|
new.Set("test", "anything")
|
|
propertiesLoadFile = mockLoadProperties(t, new, nil)
|
|
require.NotEmpty(t, new.Keys())
|
|
|
|
require.Empty(t, config.values.Keys())
|
|
// test
|
|
err := config.Load()
|
|
// assert
|
|
assert.NoError(t, err)
|
|
assert.NotEmpty(t, config.values.Keys())
|
|
|
|
}
|