-
Notifications
You must be signed in to change notification settings - Fork 263
Expand file tree
/
Copy pathwizard_test.go
More file actions
78 lines (66 loc) · 2.73 KB
/
Copy pathwizard_test.go
File metadata and controls
78 lines (66 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT
package main
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/aws/amazon-cloudwatch-agent/tool/processors"
"github.com/aws/amazon-cloudwatch-agent/tool/processors/agentconfig"
"github.com/aws/amazon-cloudwatch-agent/tool/processors/basicInfo"
"github.com/aws/amazon-cloudwatch-agent/tool/processors/collectd"
"github.com/aws/amazon-cloudwatch-agent/tool/processors/migration"
"github.com/aws/amazon-cloudwatch-agent/tool/processors/migration/windows"
"github.com/aws/amazon-cloudwatch-agent/tool/processors/ssm"
"github.com/aws/amazon-cloudwatch-agent/tool/processors/statsd"
"github.com/aws/amazon-cloudwatch-agent/tool/processors/template"
"github.com/aws/amazon-cloudwatch-agent/tool/processors/tracesconfig"
"github.com/aws/amazon-cloudwatch-agent/tool/util"
)
type MainProcessorMock struct {
mock.Mock
}
func (m *MainProcessorMock) VerifyProcessor(processor interface{}) {
m.Called(processor)
}
func TestMainMethod(t *testing.T) {
processors.StartProcessor = template.Processor
main()
}
func TestWindowsMigration(t *testing.T) {
// Do the mocking
processorMock := &MainProcessorMock{}
processorMock.On("VerifyProcessor", basicInfo.Processor).Return()
processorMock.On("VerifyProcessor", agentconfig.Processor).Return()
processorMock.On("VerifyProcessor", statsd.Processor).Return()
processorMock.On("VerifyProcessor", collectd.Processor).Return()
processorMock.On("VerifyProcessor", migration.Processor).Return()
processorMock.On("VerifyProcessor", tracesconfig.Processor).Return()
processorMock.On("VerifyProcessor", windows.Processor).Return()
processorMock.On("VerifyProcessor", ssm.Processor).Return()
MainProcessorGlobal = processorMock
// Run the functions
absPath, _ := filepath.Abs("../../tool/processors/migration/windows/testData/input1.json")
addWindowsMigrationInputs(absPath, "", "", false)
processors.StartProcessor = basicInfo.Processor
*isNonInteractiveWindowsMigration = true
startProcessing()
// Assert expected behaviour
assert.True(t, processorMock.AssertNumberOfCalls(t, "VerifyProcessor", 7))
// Assert the resultant output file as well
absPath, _ = filepath.Abs("../../tool/processors/migration/windows/testData/output1.json")
expectedConfig, err := windows.ReadNewConfigFromPath(absPath)
if err != nil {
t.Error(err)
return
}
actualConfig, err := windows.ReadNewConfigFromPath(util.ConfigFilePath())
if err != nil {
t.Error(err)
return
}
if !windows.AreTwoConfigurationsEqual(actualConfig, expectedConfig) {
t.Errorf("The generated new config is incorrect, got:\n '%v'\n, want:\n '%v'.\n", actualConfig, expectedConfig)
}
}