Skip to content

Commit

Permalink
fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommi2Day committed Oct 27, 2023
1 parent 26773f7 commit f2dcae5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 27 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog tnscli

## [v3.8.0 - 2023-10-27]
### Changed
- use go 1.21
- update workflow
- use gomodules v1.10.0
- update testinit
- fix linter issues

## [v3.7.11 - 2023-09-08]
### Fixed
- jdbc connect string format error
Expand Down
45 changes: 25 additions & 20 deletions cmd/ldap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"os"
"path"
"testing"

"github.com/tommi2day/tnscli/test"
Expand Down Expand Up @@ -71,16 +72,23 @@ DIRECTORY_SERVERS = (localhost:1389:1636, ldap:389)
DIRECTORY_SERVER_TYPE = OID
`

var tnsSource1 = path.Join(tnsAdmin, "/ldap_file_write1.ora")
var tnsSource2 = path.Join(tnsAdmin, "/ldap_file_write2.ora")

func TestOracleLdap(t *testing.T) {
var err error
var server string
var sslport int
var out = ""
var domain string
var fileTnsEntries dblib.TNSEntries

test.Testinit(t)
err = os.Chdir(test.TestDir)
require.NoErrorf(t, err, "ChDir failed")
ldapAdmin := test.TestData
tnsAdmin = test.TestData
testConfig := path.Join(test.TestDir, "tnscli.yaml")
//nolint gosec
err = os.WriteFile(ldapAdmin+"/ldap.ora", []byte(ldapOra), 0644)
require.NoErrorf(t, err, "Create test ldap.ora failed")
Expand All @@ -95,15 +103,14 @@ func TestOracleLdap(t *testing.T) {
defer common.DestroyDockerContainer(ldapContainer)
server, sslport = common.GetContainerHostAndPort(ldapContainer, "636/tcp")
// create test file to load
tnsAdmin := test.TestData
filename1 := tnsAdmin + "/ldap_file_write1.ora"

//nolint gosec
err = os.WriteFile(filename1, []byte(ldaptns), 0644)
require.NoErrorf(t, err, "Create test %s failed", filename1)
filename2 := tnsAdmin + "/ldap_file_write2.ora"
err = os.WriteFile(tnsSource1, []byte(ldaptns), 0644)
require.NoErrorf(t, err, "Create test %s failed", tnsSource1)

//nolint gosec
err = os.WriteFile(filename2, []byte(ldaptns2), 0644)
require.NoErrorf(t, err, "Create test %s failed", filename2)
err = os.WriteFile(tnsSource2, []byte(ldaptns2), 0644)
require.NoErrorf(t, err, "Create test %s failed", tnsSource2)

base := LdapBaseDn
lc := ldaplib.NewConfig(server, sslport, true, true, base, ldapTimeout)
Expand Down Expand Up @@ -135,11 +142,11 @@ func TestOracleLdap(t *testing.T) {
t.Run("Write Ldap function", func(t *testing.T) {
err = os.Chdir(test.TestDir)
require.NoErrorf(t, err, "ChDir failed")
t.Logf("load from %s", filename1)
t.Logf("load from %s", tnsSource1)

// read entries from file
fileTnsEntries, domain, err := dblib.GetTnsnames(filename1, true)
require.NoErrorf(t, err, "Parsing %s failed: %s", filename1, err)
fileTnsEntries, domain, err := dblib.GetTnsnames(tnsSource1, true)
require.NoErrorf(t, err, "Parsing %s failed: %s", tnsSource1, err)
if err != nil {
t.Fatalf("tns load returned error: %s ", err)
return
Expand All @@ -164,10 +171,10 @@ func TestOracleLdap(t *testing.T) {
err = os.Chdir(test.TestDir)
require.NoErrorf(t, err, "ChDir failed")

t.Logf("load from %s", filename2)
t.Logf("load from %s", tnsSource2)
// read entries from file
fileTnsEntries, domain, err := dblib.GetTnsnames(filename2, true)
require.NoErrorf(t, err, "Parsing %s failed: %s", filename2, err)
fileTnsEntries, domain, err = dblib.GetTnsnames(tnsSource2, true)
require.NoErrorf(t, err, "Parsing %s failed: %s", tnsSource2, err)
if err != nil {
t.Fatalf("tns load returned error: %s ", err)
return
Expand All @@ -193,8 +200,6 @@ func TestOracleLdap(t *testing.T) {
require.Equalf(t, 0, f, "Clearing TNS Ldap had %d failures", f)
})
t.Run("Write TNS to Ldap", func(t *testing.T) {
tnsAdmin := test.TestData
filename := tnsAdmin + "/ldap_file_write1.ora"
args := []string{
"ldap",
"write",
Expand All @@ -206,7 +211,7 @@ func TestOracleLdap(t *testing.T) {
"--ldap.base", LdapBaseDn,
"--ldap.binddn", LdapAdminUser,
"--ldap.bindpassword", LdapAdminPassword,
"--ldap.tnssource", filename,
"--ldap.tnssource", tnsSource1,
"--info",
"--unit-test",
}
Expand All @@ -217,8 +222,8 @@ func TestOracleLdap(t *testing.T) {
})

t.Run("Read TNS from Ldap with config file and env", func(t *testing.T) {
tnsAdmin := test.TestData
filename := tnsAdmin + "/ldap_file_read.ora"
tnsAdmin = test.TestData
filename = tnsAdmin + "/ldap_file_read.ora"
_ = os.Remove(filename)
_ = os.Setenv("TNSCLI_LDAP_BINDPASSWORD", LdapAdminPassword)
args := []string{
Expand All @@ -227,7 +232,7 @@ func TestOracleLdap(t *testing.T) {
"--ldap.host", server,
"--ldap.port", fmt.Sprintf("%d", sslport),
"--ldap.tnstarget", filename,
"--config", test.TestDir + "/tnscli.yaml",
"--config", testConfig,
"--info",
"--unit-test",
}
Expand All @@ -245,7 +250,7 @@ func TestOracleLdap(t *testing.T) {
"clear",
"--ldap.host", server,
"--ldap.port", fmt.Sprintf("%d", sslport),
"--config", test.TestDir + "/tnscli.yaml",
"--config", testConfig,
"--info",
"--unit-test",
}
Expand Down
14 changes: 9 additions & 5 deletions cmd/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"os"
"path"
"strings"
"testing"

Expand Down Expand Up @@ -86,6 +87,9 @@ const entryCount = 7

var tnsAdminDir = "testdata"

const tnsFile = "tnsnames.ora"
const sqlnetFile = "sqlnet.ora"

func TestParseTns(t *testing.T) {
var err error
test.Testinit(t)
Expand All @@ -94,16 +98,16 @@ func TestParseTns(t *testing.T) {
require.NoErrorf(t, err, "ChDir failed")

//nolint gosec
err = os.WriteFile(tnsAdminDir+"/sqlnet.ora", []byte(sqlnetora), 0644)
err = os.WriteFile(path.Join(tnsAdminDir, sqlnetFile), []byte(sqlnetora), 0644)
require.NoErrorf(t, err, "Create test sqlnet.ora failed")
//nolint gosec
err = os.WriteFile(tnsAdminDir+"/tnsnames.ora", []byte(tnsnamesora), 0644)
err = os.WriteFile(path.Join(tnsAdminDir, tnsFile), []byte(tnsnamesora), 0644)
require.NoErrorf(t, err, "Create test tnsnames.ora failed")
//nolint gosec
err = os.WriteFile(tnsAdminDir+"/ifile.ora", []byte(ifileora), 0644)
err = os.WriteFile(path.Join(tnsAdminDir, "ifile.ora"), []byte(ifileora), 0644)
require.NoErrorf(t, err, "Create test ifile.ora failed")

filename := tnsAdminDir + "/tnsnames.ora"
filename = path.Join(tnsAdminDir, tnsFile)
t.Logf("load from %s", filename)
tnsEntries, domain, err := dblib.GetTnsnames(filename, true)
t.Logf("Default Domain: '%s'", domain)
Expand Down Expand Up @@ -160,7 +164,7 @@ func TestParseTns(t *testing.T) {
},
{
name: "XE+invalid domain",
alias: "XE" + ".xx.xx",
alias: "XE.xx.xx",
success: false,
service: "",
},
Expand Down
3 changes: 2 additions & 1 deletion cmd/racinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"os"
"path"
"testing"
"time"

Expand Down Expand Up @@ -60,7 +61,7 @@ func TestRACInfo(t *testing.T) {
t.Run("Test RacInfo.ini resolution", func(t *testing.T) {
dblib.IgnoreDNSLookup = false
dblib.IPv4Only = true
addr := dblib.GetRacAdresses(racaddr, tnsAdminDir+"/racinfo.ini")
addr := dblib.GetRacAdresses(racaddr, path.Join(tnsAdminDir, racinfoFile))
assert.Equal(t, 6, len(addr), "Count not expected")
t.Logf("Addresses: %v", addr)
})
Expand Down
4 changes: 3 additions & 1 deletion cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package cmd
import (
"fmt"
"net"
"path"
"regexp"
"sort"
"strings"
Expand Down Expand Up @@ -72,6 +73,7 @@ var (

const defaultUser = "C##TCHECK"
const defaultPassword = "C0nnectMe!now"
const racinfoFile = "racinfo.ini"

var dbUser = ""
var dbPass = ""
Expand Down Expand Up @@ -154,7 +156,7 @@ func portInfo(_ *cobra.Command, args []string) (err error) {
return
}
if racinfo == "" {
racinfo = viper.GetString("tns_admin") + "/racinfo.ini"
racinfo = path.Join(viper.GetString("tns_admin"), racinfoFile)
}
entry, err := getEntry(tnsKey)
if err == nil {
Expand Down

0 comments on commit f2dcae5

Please sign in to comment.