From ca7e69768f70868df923dda593c6714fbb4c131a Mon Sep 17 00:00:00 2001 From: outdead Date: Sat, 14 Nov 2020 05:22:58 +0300 Subject: [PATCH] Add more tests, remove travis-ci integration --- .github/workflows/build.yml | 49 +++++++++ .github/workflows/golangci-lint.yml | 30 ------ .gitignore | 2 +- .golangci.yml | 14 --- .travis.yml | 4 - CHANGELOG.md | 13 ++- README.md | 7 +- telnet_test.go | 162 ++++++++++++++++++++++++++++ 8 files changed, 227 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/golangci-lint.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..18cf979 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,49 @@ +name: build + +on: + push: + tags: + - v* + branches: + - master + - develop + pull_request: + branches: [ master ] + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: ^1.15 + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: Lint + uses: golangci/golangci-lint-action@v2 + with: + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: v1.31 + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + # args: --issues-exit-code=0 + args: --config=.golangci.yml + + # Optional: show only new issues if it's a pull request. The default value is `false`. + only-new-issues: false + + - name: Get dependencies + run: | + go get -v -t -d ./... + - name: Test + run: go test -v ./... + + - name: Build + run: go build -v . diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml deleted file mode 100644 index 9868c7f..0000000 --- a/.github/workflows/golangci-lint.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: golangci-lint -on: - push: - tags: - - v* - branches: - - master - - main - pull_request: -jobs: - golangci: - name: lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.31 - - # Optional: working directory, useful for monorepos - # working-directory: somedir - - # Optional: golangci-lint command line arguments. - # args: --issues-exit-code=0 - args: --config=.golangci.yml - - # Optional: show only new issues if it's a pull request. The default value is `false`. - # only-new-issues: true diff --git a/.gitignore b/.gitignore index e299cc6..4ec852f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ .idea/ -telnet_integration_test.go +.vscode/ vendor/ diff --git a/.golangci.yml b/.golangci.yml index 7c54e7b..d44e4f5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,14 +1,7 @@ run: skip-dirs: - - test/testdata_etc - - pkg/golinters/goanalysis/(checker|passes) - - data/ - - .vscode/ - - .directory/ - - debug/ - vendor/ skip-files: - - Gopkg.lock - .gitignore - ".*_test.go$" @@ -132,10 +125,3 @@ linters: issues: exclude: - "`DefaultSettings` is a global variable" # (gochecknoglobals) - -# golangci.com configuration -# https://github.com/golangci/golangci/wiki/Configuration -service: - golangci-lint-version: 1.31.x # use the fixed version to not introduce new linters unexpectedly - prepare: - - echo "here I can run custom commands, but no preparation needed for this repo" diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 156b095..0000000 --- a/.travis.yml +++ /dev/null @@ -1,4 +0,0 @@ -language: go - -go: - - 1.15.x diff --git a/CHANGELOG.md b/CHANGELOG.md index a680a7b..83d6819 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,19 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +## [v1.0.1] - 2020-11-14 +### Added +- Added the ability to run the help command on a real 7 Days to Die server. To do this, set environment variables +`TEST_7DTD_SERVER=true`, `TEST_7DTD_SERVER_ADDR` and `TEST_7DTD_SERVER_PASSWORD` with address and password from +7 Days to Die remote console. + +### Changed +- Changed CI workflows and related badges. Integration with Travis-CI was changed to GitHub actions workflow. Golangci-lint +job was joined with tests workflow. + ## v1.0.0 - 2020-10-06 ### Added - Initial implementation. -[Unreleased]: https://github.com/gorcon/telnet/compare/v1.0.0...HEAD +[Unreleased]: https://github.com/gorcon/telnet/compare/v1.0.1...HEAD +[v1.0.1]: https://github.com/gorcon/telnet/compare/v1.0.0...v1.0.1 diff --git a/README.md b/README.md index 51ca1f1..180f3bb 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ -# telnet -[![golangci-lint](https://github.com/gorcon/telnet/workflows/golangci-lint/badge.svg)](https://github.com/gorcon/telnet/actions) -[![Go Report Card](https://goreportcard.com/badge/github.com/gorcon/telnet)](https://goreportcard.com/report/github.com/gorcon/telnet) -[![Build Status](https://travis-ci.org/gorcon/telnet.svg?branch=master)](https://travis-ci.org/gorcon/telnet) +# Telnet +[![GitHub Build](https://github.com/gorcon/telnet/workflows/build/badge.svg)](https://github.com/gorcon/telnet/actions) [![Coverage](https://gocover.io/_badge/github.com/gorcon/telnet?0 "coverage")](https://gocover.io/github.com/gorcon/telnet) +[![Go Report Card](https://goreportcard.com/badge/github.com/gorcon/telnet)](https://goreportcard.com/report/github.com/gorcon/telnet) [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/gorcon/telnet) 7 Days to Die remote access to game [Command Console](https://7daystodie.gamepedia.com/Command_Console). This is not full [TELNET](https://en.wikipedia.org/wiki/Telnet) protocol implementation. diff --git a/telnet_test.go b/telnet_test.go index 2403672..b638323 100644 --- a/telnet_test.go +++ b/telnet_test.go @@ -2,7 +2,10 @@ package telnet import ( "bytes" + "encoding/json" "fmt" + "os" + "strings" "testing" "time" @@ -117,6 +120,156 @@ func TestConn_Execute(t *testing.T) { assert.NoError(t, err) assert.Equal(t, fmt.Sprintf("Please enter password:%s%s%s%s%s", CRLF, AuthSuccess, CRLF, MockCommandHelpResponse, CRLF), result) }) + + if run := getVar("TEST_7DTD_SERVER", "false"); run == "true" { + addr := getVar("TEST_7DTD_SERVER_ADDR", "172.22.0.2:8081") + password := getVar("TEST_7DTD_SERVER_PASSWORD", "banana") + + t.Run("7dtd server", func(t *testing.T) { + needle := `*** List of Commands *** + admin => Manage user permission levels + aiddebug => Toggles AIDirector debug output. + audio => Watch audio stats + automove => Player auto movement + ban => Manage ban entries + bents => Switches block entities on/off + BiomeParticles => Debug + buff => Applies a buff to the local player + buffplayer => Apply a buff to a player + chunkcache cc => shows all loaded chunks in cache + chunkobserver co => Place a chunk observer on a given position. + chunkreset cr => resets the specified chunks + commandpermission cp => Manage command permission levels + creativemenu cm => enables/disables the creativemenu + debuff => Removes a buff from the local player + debuffplayer => Remove a buff from a player + debugmenu dm => enables/disables the debugmenu ` + ` + debugshot dbs => Lets you make a screenshot that will have some generic info +on it and a custom text you can enter. Also stores a list +of your current perk levels in a CSV file next to it. + debugweather => Dumps internal weather state to the console. + decomgr => ` + ` + dms => Gives control over Dynamic Music functionality. + dof => Control DOF + enablescope es => toggle debug scope + exhausted => Makes the player exhausted. + exportcurrentconfigs => Exports the current game config XMLs + exportprefab => Exports a prefab from a world area + floatingorigin fo => ` + ` + fov => Camera field of view + gamestage => usage: gamestage - displays the gamestage of the local player. + getgamepref gg => Gets game preferences + getgamestat ggs => Gets game stats + getoptions => Gets game options + gettime gt => Get the current game time + gfx => Graphics commands + givequest => usage: givequest questname + giveself => usage: giveself itemName [qualityLevel=6] [count=1] [putInInventory=false] [spawnWithMods=true] + giveselfxp => usage: giveselfxp 10000 + help => Help on console and specific commands + kick => Kicks user with optional reason. "kick playername reason" + kickall => Kicks all users with optional reason. "kickall reason" + kill => Kill a given entity + killall => Kill all entities + lgo listgameobjects => List all active game objects + lights => Debug views to optimize lights + listents le => lists all entities + listplayerids lpi => Lists all players with their IDs for ingame commands + listplayers lp => lists all players + listthreads lt => lists all threads + loggamestate lgs => Log the current state of the game + loglevel => Telnet/Web only: Select which types of log messages are shown + mem => Prints memory information and unloads resources or changes garbage collector + memcl => Prints memory information on client and calls garbage collector + occlusion => Control OcclusionManager + pirs => tbd + pois => Switches distant POIs on/off + pplist => Lists all PersistentPlayer data + prefab => ` + ` + prefabupdater => ` + ` + profilenetwork => Writes network profiling information + profiling => Enable Unity profiling for 300 frames + removequest => usage: removequest questname + repairchunkdensity rcd => check and optionally fix densities of a chunk + saveworld sa => Saves the world manually. + say => Sends a message to all connected clients + ScreenEffect => Sets a screen effect + setgamepref sg => sets a game pref + setgamestat sgs => sets a game stat + settargetfps => Set the target FPS the game should run at (upper limit) + settempunit stu => Set the current temperature units. + settime st => Set the current game time + show => Shows custom layers of rendering. + showalbedo albedo => enables/disables display of albedo in gBuffer + showchunkdata sc => shows some date of the current chunk + showClouds => Artist command to show one layer of clouds. + showhits => Show hit entity locations + shownexthordetime => Displays the wandering horde time + shownormals norms => enables/disables display of normal maps in gBuffer + showspecular spec => enables/disables display of specular values in gBuffer + showswings => Show melee swing arc rays + shutdown => shuts down the game + sleeper => Show sleeper info + smoothworldall swa => Applies some batched smoothing commands. + sounddebug => Toggles SoundManager debug output. + spawnairdrop => Spawns an air drop + spawnentity se => spawns an entity + spawnentityat sea => Spawns an entity at a give position + spawnscouts => Spawns zombie scouts + SpawnScreen => Display SpawnScreen + spawnsupplycrate => Spawns a supply crate where the player is + spawnwanderinghorde spawnwh => Spawns a wandering horde of zombies + spectator spectatormode sm => enables/disables spectator mode + spectrum => Force a particular lighting spectrum. + stab => stability + starve hungry food => Makes the player starve (optionally specify the amount of food you want to have in percent). + switchview sv => Switch between fpv and tpv + SystemInfo => List SystemInfo + teleport tp => Teleport the local player + teleportplayer tele => Teleport a given player + thirsty water => Makes the player thirsty (optionally specify the amount of water you want to have in percent). + traderarea => ... + trees => Switches trees on/off + updatelighton => Commands for UpdateLightOnAllMaterials and UpdateLightOnPlayers + version => Get the currently running version of the game and loaded mods + visitmap => Visit an given area of the map. Optionally run the density check on each visited chunk. + water => Control water settings + weather => Control weather settings + weathersurvival => Enables/disables weather survival + whitelist => Manage whitelist entries + wsmats workstationmaterials => Set material counts on workstations. + xui => Execute XUi operations + xuireload => Access xui related functions such as reinitializing a window group, opening a window group + zip => Control zipline settings` + + needle = strings.Replace(needle, "\n", "\r\n", -1) + needle = strings.Replace(needle, "some generic info\r\n", "some generic info\n", -1) + needle = strings.Replace(needle, "Also stores a list\r\n", "Also stores a list\n", -1) + + conn, err := Dial(addr, password) + if err != nil { + t.Fatal(err) + } + defer func() { + assert.NoError(t, conn.Close()) + }() + + result, err := conn.Execute("help") + assert.NoError(t, err) + + if !strings.Contains(result, needle) { + diff := struct { + R string + N string + }{R: result, N: needle} + + js, _ := json.Marshal(diff) + fmt.Println(string(js)) + + t.Error("response is not contain needle string") + } + }) + } } func TestConn_Interactive(t *testing.T) { @@ -164,3 +317,12 @@ func TestConn_Interactive(t *testing.T) { assert.Equal(t, fmt.Sprintf("Please enter password:%s%s%s%s%s", CRLF, AuthSuccess, CRLF, MockCommandHelpResponse, CRLF), w.String()) }) } + +// getVar returns environment variable or default value. +func getVar(key string, fallback string) string { + if value := os.Getenv(key); value != "" { + return value + } + + return fallback +}